using System.Net.WebSockets;
using Microsoft.EntityFrameworkCore;
using UniversalAdminSystem.Domian.Core.ValueObjects;
using UniversalAdminSystem.Domian.UserConversations.Aggregates;
using UniversalAdminSystem.Domian.UserConversations.IRepository;
using UniversalAdminSystem.Infrastructure.Persistence.DbContexts;

namespace UniversalAdminSystem.Infrastructure.Persistence.Repositories;

public class ConversationsRepository : BaseRepository<Conversations>, IConversationsRepository
{
    public ConversationsRepository(UniversalAdminSystemDbContext dbContext) : base(dbContext)
    {
    }

    public async Task<IEnumerable<Conversations>> GetByUserIdAsync(Guid userId)
    {
        var usersid = UserId.Create(userId);
        var list = await _TDs.Where(c => c.UserId == usersid).OrderBy(c=>c.UpdateDate).AsNoTracking().ToListAsync();
        return list;
    }

    public async Task RemoveByUserIdAsync(Guid userId)
    {
        var usersId = UserId.Create(userId);
        await _TDs.Where(c => c.UserId == usersId).ExecuteDeleteAsync();
    }

    public async Task RemoveConversation(Guid ConsId)
    {
        var ConId = ConversationId.Create(ConsId);
        await _TDs.Where(c => c.Id == ConId).ExecuteDeleteAsync();
    }
}